#!/usr/bin/python
#coding:utf-8

import wechat_pb2
from struct import pack,unpack

# airsync = wechat_pb2.InitRequest();
authReq = wechat_pb2.AuthRequest();
authRes = wechat_pb2.AuthResponse();

# authReq   FE 01 00 1D 27 11 00 01 0A 00 18 84 80 04 20 01 28 02 3A 06 C6 00 00 00 00 01 62 01 00
# authRes   FE 01 00 0E 4E 21 00 01 0A 02 08 00 12 00
# test      FE 01 00 10 27 13 00 02 0A 00 1A 04 11 22 33 44
# init      FE 01 00 19 4E 23 00 02 0A 02 08 00 10 B4 24 18 F8 AC 01 20 D1 BB CA BF 07
# custom push FE 01 00 13 75 31 00 00 0A 00 12 04 74 70 3D 31 18 91 4E

def main_func():
    print("Hello World");
    bq = wechat_pb2.BaseRequest();
    print(bq.SerializeToString());
    """
    airsync.BaseRequest = bq;
    airsync.RespFieldFilter = 'A';
    airsync.Challenge = 'B';
    print(airsync.SerializeToString());
    """
    # airsync.ParseFromString('\x0a\x02\x08\x00\x10\xb4\x24\x18\xf8\xac\x01\x20\xd1\xbb');
    # print(airsync.Challenge);
    # print(airsync.encode_to_bytes());
    authReq.ParseFromString("\x0A\x00\x18\x84\x80\x04\x20\x01\x28\x02\x3A\x06\xC6\x00\x00\x00\x00\x01");
    print(authReq.SerializeToString());
    bp = authReq.BaseRequest.SerializeToString();
    print(len(bp));
    md5 = authReq.Md5DeviceTypeAndDeviceId;
    print(len(md5));
    # print(authReq.BaseRequest.SerializeToString());
    print(authReq.ProtoVersion);
    print(authReq.AuthProto);
    method = authReq.AuthMethod;
    print(method);
    print(len(authReq.AesSign));
    print(len(authReq.MacAddress));
    mac = unpack('6B', authReq.MacAddress);
    print("MAC=%02X:%02X:%02X:%02X:%02X:%02X" % mac);
    authRes.ParseFromString('\x0A\x02\x08\x00');
    bp = authRes.BaseResponse;
    print (bp.ErrCode);
    # print "%02X %02X" % unpack('2B', bp);
    print(len(authRes.AesSessionKey));
    print(authRes.AesSessionKey);

if __name__ == '__main__':
    main_func();
